package com.qindian.coupontest;

import android.util.Log;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Author: Li
 * Date: 2018/4/28 0028
 * Description:
 */

public class RetrofitHelper {
    private static Retrofit retrofit;
    public static HttpService createService() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl("http://tk-api.d5lu.com/app_api/")
                    .client(new OkHttpClient
                            .Builder()
                            .addInterceptor(new Interceptor() {
                                @Override
                                public Response intercept(Chain chain) throws IOException {
                                    Request request=chain.request();
                                    Log.e("tag", "intercept: "+request.url().toString());
                                    return chain.proceed(request);
                                }
                            })
                            .build())
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .build();
        }
        return retrofit.create(HttpService.class);
    }
}
